<!-- 视图分组 -->

<template>
  <div
    class="MapLabel-MapView-group"
    :class="pointClass"
    :style="pointStyle"
    @mouseenter="mouseEnter"
    @mouseleave="mouseLeave"
  >
    <div class="Secure-MapView-point-icon" :style="iconStyle" @click.stop="toEdit">
      <div class="flexCC flexCol" :style="`background: ${iconColor}`">
        <div>{{ nameTop || '-' }}</div>
        <div v-if="nameBottom">{{ nameBottom }}</div>
      </div>
    </div>

    <div class="Secure-MapView-point-panel">
      <div>
        <label>所在{{ CORE.MAP.REGION }}</label>
        <span class="ellips">{{ CORE.REGION.NAME[obj.areaId] || obj.areaName }}</span>
      </div>

      <div>
        <label>标签类型</label>
        <span class="ellips">{{ CORE.dict(map_DICT.LABEL_TYPE, obj.typeValue) || obj.typeLabel }}</span>
      </div>

      <div v-for="(item, i) in obj.properties" :key="item.id || i">
        <label>{{ item.propertyLabel }}</label>
        <span class="ellips">{{ transText(item) }}</span>
      </div>

      <span class="DangerColor" @click.stop="toDel">删除</span>
      <span class="PrimaryColor" @click.stop="map_openEdit(obj)">修改</span>
    </div>
  </div>
</template>

<script>
// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import ViewPoint from '@admin/views/Secure/mixMap/MapView/ViewPoint'

// ============================== 导出组件 ============================== //

export default CORE.extend(ViewPoint, {
  /**
   * 名称定义 (实际使用名称)
   */
  name: 'ViewGroup',

  /**
   * 混入列表 (配置选项合并)
   */
  mixins: [CORE.mixWeb('map', 'map_'), CORE.mixSelect('group', 'group_')],

  /**
   * 计算属性 (慎用箭头函数)
   */
  computed: {
    ...ViewPoint.computed,

    /**
     * 图标颜色
     */
    iconColor() {
      const { obj: { labelGroupId }, group_selectDict } = this
      return CORE.dict(group_selectDict, labelGroupId, 2)
    },

    /**
     * 名称上一行
     */
    nameTop() {
      const { obj: { labelGroupName: name } } = this
      return name.length < 3 ? name : name.slice(0, 2)
    },

    /**
     * 名称下一行
     */
    nameBottom() {
      const { obj: { labelGroupName: name } } = this
      return name.length < 3 ? '' : name.slice(2)
    },
  },

  /**
   * 本地方法 (轻量重要在前)
   */
  methods: {
    ...ViewPoint.methods,

    /**
     * 转换文本
     */
    transText({ dataTypeValue: type, propertyValue: value }) {
      switch (type) {
        case 'input_type_digit': return CORE.num(value)
        case 'input_type_date': return CORE.dateStr(value)
        case 'input_type_time': return CORE.timeStr(value)
        default: return value
      }
    },
  },
})
</script>
